﻿#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="UserPair.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2010, 2011
//       Roland Rosenkranz (Glatzemann@email.de)
// </copyright>
// <license>
//   This file is part of starLiGHT.Collision.
//
//   starLiGHT.Collision is free software: you can redistribute it and/or modify
//   it under the terms of the GNU Lesser General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   starLiGHT.Collision is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Lesser General Public License for more details.
//
//   You should have received a copy of the GNU Lesser General Public License
//   along with starLiGHT.Collision. If not, see http://www.gnu.org/licenses/.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.Collision are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 3231                  $:  Revision of last commit *
// * $Author:: unknown            $:  Author of last commit   *
// * $Date:: 2011-01-11 21:44:51 #$:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.Collision
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using starLiGHT;

    #endregion

    public class UserPair<T> : IEquatable<UserPair<T>>
    {
        public UserPair(int id0, int id1, T object0, T object1)
        {
            if (id0 < id1)
            {
                this.ID0 = id0;
                this.ID1 = id1;
                this.object0 = object0;
                this.object1 = object1;
            }
            else if (id0 > id1)
            {
                this.ID0 = id1;
                this.ID1 = id0;
                this.object0 = object1;
                this.object1 = object0;
            }
            else
            {
                throw new InvalidOperationException("object can't be paired with itself...");
            }
        }

        public int ID0 { get; private set; }

        public int ID1 { get; private set; }

        public T object0 { get; private set; }

        public T object1 { get; private set; }

        public override int GetHashCode()
        {
            int key = (this.ID0 << 16) | this.ID1;
            key = ~key + (key << 15);
            key = key ^ (key >> 12);
            key = key + (key << 2);
            key = key ^ (key >> 4);
            key = key * 2057;
            key = key ^ (key >> 16);
            return key;
        }

        public bool Equals(UserPair<T> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            return (this.ID0 == other.ID0) && (this.ID1 == other.ID1);
        }
    }
}
